package edu.gdkm.controller;

import edu.gdkm.common.Result;
import edu.gdkm.controller.request.BorrowPageRequest;
import edu.gdkm.entity.Borrow;
import edu.gdkm.entity.Retur;
import edu.gdkm.service.IBorrowService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

//解决跨域问题
@CrossOrigin
@RestController
@RequestMapping("/borrow")
public class BorrowController {
    @Autowired
    IBorrowService borrowService;



    /**
     * 修改信息
     * @param obj
     * @return
     */
    @PutMapping("/update")
    public Result update(@RequestBody Borrow obj){
        borrowService.update(obj);
        return Result.success();
    }
    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable Integer id){
        borrowService.deleteById(id);
        return Result.success();
    }



    /**
     * 通过id获取用户数据 用于=>(修改,删除用户)
     * @return
     */
    @GetMapping("/{id}")
    public Result getById(@PathVariable Integer id){
        Borrow obj = borrowService.getById(id);
        return Result.success(obj);
    }
    /**
     * 新增用户
     * @return
     */
    @PostMapping("/save")
    public Result save(@RequestBody Borrow obj){

        borrowService.save(obj);
        return Result.success();
    }

    /**
     * 查询所有
     * @return
     */
    @GetMapping("/list")
    public Result list(){
        List<Borrow> list = borrowService.list();
        return Result.success(list);
    }

    /**
     * 分页查询 模糊查询
     * @param
     * @return
     */
    @GetMapping("/page")
    public Result page(BorrowPageRequest pageRequest){
        return Result.success(borrowService.page(pageRequest));
    }
    @PostMapping("/saveRetur")
    public Result save(@RequestBody Retur obj){

        borrowService.saveRetur(obj);
        return Result.success();
    }
    @GetMapping("/pageRetur")
    public Result pageRetur(BorrowPageRequest pageRequest){
        return Result.success(borrowService.pageRetur(pageRequest));
    }
    @DeleteMapping("/deleteRetur/{id}")
    public Result deleteRetur(@PathVariable Integer id){
        borrowService.deleteReturById(id);
        return Result.success();
    }
}
